package com.balloon.springboot.security.service.impl;

import com.balloon.springboot.core.exception.BaseExceptionEnums;
import com.balloon.springboot.security.entity.SecurityUser;
import com.balloon.springboot.security.entity.SystemUser;
import com.balloon.springboot.security.service.UserSmsDetailsService;
import com.gitee.aurora.core.comm.AuroraJdbcTemplate;
import com.gitee.aurora.core.exception.BusinessRuntimeException;
import com.gitee.aurora.core.utils.MapToObj;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

/**
 * 短信登录校验逻辑
 *
 * <p>因为 balloon-springboot 项目不提供 ORM 框架, 具体数据校验逻辑需要第三方实现, 默认的实现仅提示作用, 不包含任何实现逻辑</p>
 *
 * @author liaofuxing
 * @date 2020/07/16 15:53
 */
public class DefaultUserSmsDetailsServiceImpl implements UserSmsDetailsService {
    @Autowired
    AuroraJdbcTemplate auroraJdbcTemplate;

    @Override
    public SecurityUser loadUserByPhone(String phone) throws BusinessRuntimeException {
        String sql = "SELECT * FROM SYSTEM_USER WHERE PHONE = ?";
        Map<String, Object> stringObjectMap = auroraJdbcTemplate.queryForMap(sql, phone);
        return MapToObj.mapUpperCaseToObj(stringObjectMap, SystemUser.class);
    }
}
